#include "main.h"

/*

#define FADE 30
#define FADEDIV (FADE / 5)

void fadein() {

	u8 i;
	for (i = 0; i < FADE; ++i) {
		pal_bright(i / FADEDIV);
		waitvblank();
	}
}

void fadeout() {

	u8 i;
	for (i = 0; i < FADE; ++i) {
		pal_bright(4 - (i / FADEDIV));
		waitvblank();
	}

}

*/

#pragma code-name (push, "LOWPRG")

// Set the attribute of this 16x16 block in NT A
void pal_nt(u8 x, u8 y, const u8 col) {

	u8 byte;
	u8 offx, offy;
	addr = 0x23c0;

	x /= 2;
	y /= 2;

	offx = x / 2;
	offy = y / 2;

	addr += (offy << 3) + offx;

	vram_adr(addr);
	vram_read(&byte, 1);

	// Which quadrant?
	offx *= 2;
	offy *= 2;

	x -= offx;
	y -= offy;

	if (!x && !y) {
		// Top-left
		byte &= ~0x3;
		byte |= col;
	} else if (!x && y) {
		// Bottom-left
		byte &= ~0x30;
		byte |= col << 4;
	} else if (x && !y) {
		// Top-right
		byte &= ~0xc;
		byte |= col << 2;
	} else {
		// Bottom-right
		byte &= ~0xc0;
		byte |= col << 6;
	}

	vram_adr(addr);
	vram_write(&byte, 1);
}

void str(const char *msg) {

	while (*msg) {
		vram_put(*msg - ' ');
		msg++;
	}
}

#pragma code-name (pop)
